Repository navigation
feat: instance governance — attach, liveness, handshake, graceful exit, atomic state (#417) - #419
Merged
Merged
Conversation
…t, atomic state (#417) L1 identity: proxy-origin file upgraded to JSON {origin, instanceId, pid, startedAt, config fingerprint, launchToken} with atomic writes and legacy plain-string read compatibility; /__bili/health echoes instanceId/pid/startedAt (#403 read side). L2 attach-or-spawn (#394): ensureProxyRunning attaches to a healthy, config-compatible instance instead of doubling writers over one sessions dir; stateDir instances.json registry prunes dead pids and warns loudly on dual live instances. L3 handshake (#407): no more probe-release-rebind TOCTOU — the child self- binds, retries EADDRINUSE (+1 up to 16, then ephemeral) when launched with BILI_LAUNCH_TOKEN, and reports the real origin via the instance file; forced --debug on spawned proxies removed (12MB/day logs). L4 graceful exit (#414): launcher children watch BILI_PARENT_PID and run the flush path when the parent dies (Windows TerminateProcess never flushed); stopProxy is a no-op kill on win32 (the watcher owns shutdown) and leaves attached instances alone. L5 state hygiene (#406, #403 write side): plugin-conversations.json gets tmp+rename atomic writes, a dirty flag (dying paths no longer rewrite the table), and corrupt-byte preservation + warning instead of silent zeroing; plugin install refuses to freeze dead/unverifiable origins into client configs (BILI_MCP_PROXY still wins). L6 overlay antidote (#410): mergeOverlayEntry threads the generatedFile exclusion through directory recursion (nested models.yml can no longer be promoted into the real home); dead proxy URLs baked into a real models.yml are unpacked mechanically on launch (live origins kept).
6 tasks
Contributor
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-419Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr419.tgz
npm install -g packageThis comment is automatically updated on each push. |
…rs to the parent-gone watcher CI caught the stale assertion: win32 stopProxy is intentionally a no-op (child.kill is TerminateProcess, zero flush); the test now pins that contract on both platforms instead of assuming POSIX behavior.
This was referenced Sep 1, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #394, fixes #403, fixes #407, fixes #414, fixes #410, fixes #406. Umbrella design: #417.
What changed (six layers, one keystone)
L1 — identity + liveness (#403 read side)
proxy-originfile upgraded to JSON{origin, instanceId, pid, startedAt, host, port, passthrough, mitmDomains, modelWindows, launchToken}— atomic write (tmp+fsync+rename), legacy plain-string still readable (src/instance.ts)/__bili/healthechoes{instanceId, pid, startedAt}so readers verify they are talking to the recorded instance, not a port-squatterL2 — attach-or-spawn (#394)
ensureProxyRunningnow probes the recorded instance first: healthy + config-compatible (host/passthrough/mitmDomains/modelWindows) → attach and reuse, no second writer over the same sessions dirstateDir()/instances.jsonregistry: every proxy registers at listen, dead pids pruned, a second live instance triggers a loud[instances]warningL3 — handshake kills the TOCTOU (#407)
BILI_LAUNCH_TOKEN, retries EADDRINUSE (port+1 ×16 → ephemeral) instead of dying--debugon spawned proxies removed (12MB/day)L4 — graceful exit (#414)
BILI_PARENT_PIDand run the existing flush path when the parent disappears (≤2s) — Windows' TerminateProcess never gave them a chancestopProxy: win32 no longer hard-kills (the watcher owns shutdown); attached instances are never killedL5 — state hygiene (#406, #403 write side)
plugin-conversations.json: atomic writes + dirty flag (a dying EADDRINUSE path no longer rewrites the table) + corrupt bytes are preserved beside the original with a warning instead of silently zeroing every routebili plugin installrefuses to freeze a dead/unverifiable origin into persistent client configs (BILI_MCP_PROXYenv still wins)L6 — overlay antidote (#410)
mergeOverlayEntrythreads thegeneratedFileexclusion through directory recursion — a nestedmodels.ymlcan no longer be promoted into the real homemodels.ymlare unpacked mechanically on launch (the original upstream is embedded in the/bili/path); live origins are kept (deliberate power-user wiring)Verification
attaching to running proxy (pid …), zero spawns ✓Notes for reviewers
tests/launcher.test.ts's old "always spawns a fresh proxy, never reuses a listener" test is renamed/replaced — the never-reuse policy is exactly what 无单实例守卫:多个 bili 代理进程并存共写 sessions 目录,伴随孤儿 ref、有注册表无 transcript、计数自相矛盾的污染簇 #394/ACP_PASSTHROUGH one-click silent kill of all compression: no logs / no banners / panel invisible and non-clearable, all sibling env knobs take effect in silence | ACP_PASSTHROUGH 一键静默关死全部压缩:无日志/无横幅/面板不可见且不可清除,同族 env 旋钮全部生效于无声 #403/launcher 端口 TOCTOU(探测-释放-重bind 无重试):可静默挂上陌生 bili 或 20s 挂死;且被启动代理强制 --debug 制造 12MB/天日志 #407 suffered from; the replacement tests pin the new attach policy and its incompatibility escape hatch.kill(pid, 0)which Node implements via OpenProcess on Windows.